<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>demo</title>
    <style>
      div {
        padding: 50px;
      }
      #father {
        background-color: #58bc58;
      }
      #son {
        background-color: pink;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <h1>1.阻止事件冒泡</h1>
      <div id="father" @click="father">
        <div id="son" @click.stop="son"></div>
      </div>

      <h1>2.阻止默认行为</h1>
      <a href="http://www.baidu.com" @click.prevent="tomy">百度</a>
    </div>
  </body>
  <script src="../node_modules/vue/dist/vue.js"></script>
  <script>
    new Vue({
      el: "#app",
      data: {},
      methods: {
        father() {
          alert("我是老爸");
        },
        son() {
          alert("我是儿子");
        },
        tomy() {
          window.open("https://cn.vuejs.org/");
        },
      },
    });
  </script>
</html>
